package com.ruoyi.zhgd.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ruoyi.zhgd.util.PageUtils;
import com.ruoyi.zhgd.util.Query;
import com.ruoyi.zhgd.dto.ZjHntScaleDto;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;

import cn.dev33.satoken.annotation.SaCheckLogin;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.zhgd.domain.vo.ZjHntScaleRefVo;
import com.ruoyi.zhgd.domain.bo.ZjHntScaleRefBo;
import com.ruoyi.zhgd.service.IZjHntScaleRefService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 配比   自建-混凝土-配比
 *
 * @author yhy
 * @date 2023-09-22
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/zhgd/hntScaleRef")
public class ZjHntScaleRefController extends BaseController {

    private final IZjHntScaleRefService iZjHntScaleService;

    /**
     * 查询配比   自建-混凝土-配比列表
     */
    @SaCheckLogin
    @GetMapping("/list")
    public TableDataInfo<ZjHntScaleRefVo> list(ZjHntScaleRefBo bo, PageQuery pageQuery) {
        return iZjHntScaleService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出配比   自建-混凝土-配比列表
     */
    @SaCheckLogin
    @Log(title = "配比   自建-混凝土-配比", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ZjHntScaleRefBo bo, HttpServletResponse response) {
        List<ZjHntScaleRefVo> list = iZjHntScaleService.queryList(bo);
        ExcelUtil.exportExcel(list, "配比   自建-混凝土-配比", ZjHntScaleRefVo.class, response);
    }

    /**
     * 获取配比   自建-混凝土-配比详细信息
     *
     * @param id 主键
     */
    @SaCheckLogin
    @GetMapping("/{id}")
    public R<ZjHntScaleDto> getInfo( @PathVariable Long id) {
        return R.ok(iZjHntScaleService.queryById(id));
    }

  /*  *//**
     * 新增配比   自建-混凝土-配比
     *//*
    @SaCheckLogin
    @Log(title = "配比   自建-混凝土-配比", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ZjHntScaleRef bo) {
        return toAjax(iZjHntScaleService.insertByBo(bo));
    }*/

  /*  *//**
     * 修改配比   自建-混凝土-配比
     *//*
    @SaCheckLogin
    @Log(title = "配比   自建-混凝土-配比", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ZjHntScaleRef bo) {
        return toAjax(iZjHntScaleService.updateByBo(bo));
    }
*/
   /* *//**
     * 删除配比   自建-混凝土-配比
     *
     * @param ids 主键串
     *//*
    @SaCheckLogin
    @Log(title = "配比   自建-混凝土-配比", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iZjHntScaleService.deleteWithValidByIds(Arrays.asList(ids), true));
    }*/

    /**
     * 查询混凝土列表
     * @param params
     * @param pageNum
     * @param pageSize
     * @return
     */
    @SaCheckLogin
    @GetMapping("/hntScaleList")
    public R hntScaleList(@RequestParam Map<String,Object> params,
                          @RequestParam(value = "pageNum" , required = false) Integer pageNum,
                          @RequestParam(value = "pageSize" , required = false) Integer pageSize){
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("page",pageNum);
        paramMap.put("limit",pageSize);
        PageUtils pageUtils = iZjHntScaleService.hntScaleList(new Query(paramMap).getPage(), params);
        return R.ok(pageUtils);
    }

    /**
     * 新增
     * @param zjHntScaleDto
     * @return
     */
    @SaCheckLogin
    @Log(title = "配比   自建-混凝土-配比", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R add(@RequestBody ZjHntScaleDto zjHntScaleDto){
        iZjHntScaleService.add(zjHntScaleDto);
        return R.ok();
    }

    /**
     * 修改
     * @param zjHntScaleDto
     * @return
     */
    @SaCheckLogin
    @Log(title = "配比   自建-混凝土-配比", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/edit")
    public R Redit(@RequestBody ZjHntScaleDto zjHntScaleDto ){
        iZjHntScaleService.edit(zjHntScaleDto);
        return R.ok();
    }


    /**
     * @Title: page
     * @Description: 混凝土配比删除
     * @param id 查询条件
     * @return Result 混凝土配比删除
     */
    @DeleteMapping("/{id}")
    public R<String> remove(@PathVariable("id") String id) {
        iZjHntScaleService.removeRequires(id);
        return R.ok("操作成功！");
    }


}
